/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.imports;

import cz.mzk.rehan.commons.DatastreamId;
import cz.mzk.rehan.commons.Namespaces;
import org.dom4j.Document;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 */
public class DatastreamFactory {

    public static InlineXmlDs createInlineDatastream(Document doc, DatastreamId dsId) {
        String idStr = dsId.toString();
        if (DatastreamId.BIBLIO_MODS.toString().equals(idStr)) {
            return new InlineXmlDs(doc, dsId, "BIBLIO_MODS Record", Namespaces.mods.getURI(), "text/xml");
        } else if (DatastreamId.DC.toString().equals(idStr)) {
            return new InlineXmlDs(doc, dsId, "Dublin Core Record", Namespaces.dc.getURI(), "text/xml");
        } else if (DatastreamId.RELS_EXT.toString().equals(idStr)) {
            return new InlineXmlDs(doc, dsId, "RDF Statements", Namespaces.rdf.getURI(), "application/rdf+xml");
        } else if (DatastreamId.TEI.toString().equals(idStr)) {
            return new InlineXmlDs(doc, dsId, "TEI Record", Namespaces.tei.getURI(), "text/xml");
        } else {
            throw new RuntimeException("Unsupported inline datastream " + dsId.toString());
        }
    }

    public static ExternallyReferencedDs createExternalyReferencedDs(String url, DatastreamId dsId) {
        String idStr = dsId.toString();
        if (DatastreamId.IMG_FULL.toString().equals(idStr)) {
            return new ExternallyReferencedDs(ReferenceType.URL, url, dsId, "Image in full resolution", null, "image/jpeg");
        } else if (DatastreamId.IMG_THUMB.toString().equals(idStr)) {
            return new ExternallyReferencedDs(ReferenceType.URL, url, dsId, "Image thumbnail", null, "image/jpeg");
        } else if (DatastreamId.POLICY.toString().equals(idStr)) {
            return new ExternallyReferencedDs(ReferenceType.URL, url, dsId, "POLICY", null, "text/xml");
        } else {
            throw new RuntimeException("Unsupported externaly referenced datastream " + dsId.toString());
        }
    }

    public static ReferencedManagedDs createReferencedManagedDs(String url, DatastreamId dsId, String mimeType) {
        String idStr = dsId.toString();
        if (DatastreamId.IMG_FULL.toString().equals(idStr)) {
            return new ReferencedManagedDs(ReferenceType.URL, url, dsId, "Image in full resolution", null, mimeType);
        } else if (DatastreamId.IMG_THUMB.toString().equals(idStr)) {
            return new ReferencedManagedDs(ReferenceType.URL, url, dsId, "Image thumbnail", null, mimeType);
        } else {
            throw new RuntimeException("Unsupported managed datastream (from referenced source)" + dsId.toString());
        }
    }
}
